init("0", 2)
luaExitIfCall(true)

SCREEN_HEIGHT, SCREEN_WIDTH = getScreenSize();
buttonWidth, buttonHeight = 0.0757 * SCREEN_WIDTH, 0.159 * SCREEN_HEIGHT
-- buttonWidth, buttonHeight = 0.0896 * SCREEN_WIDTH, 0.167 * SCREEN_HEIGHT
COCAPP_IDENTIFIER = "com.supercell.magic"

function findTroopButtonColors(x1, y1, x2, y2)
    local w, h = x2 - x1, y2 - y1
    local startX, startY = x1 + (w * 3 / 8), y1 + (h * 3 / 8)
    local dx, dy = w / 4, h / 4
    for i = 1, 2 do
        for j = 1, 2 do
            tmpX, tmpY = math.floor(0.5 + startX + dx * (j - 1)), math.floor(0.5 + startY + dy * (i - 1))
            color = getColor(tmpX, tmpY)
            wLog("color", "x:" .. tmpX .. " y:" .. tmpY .. " color:" .. string.format("0x%06X",color))
        end
    end
end

function saveColors()
    local startX, startY = 0.085 * SCREEN_WIDTH, 0.796 * SCREEN_HEIGHT
    -- local startX, startY = 0.0083 * SCREEN_WIDTH, 0.7922 * SCREEN_HEIGHT
    for i = 1, 11 do
        x = startX + (i - 1) * buttonWidth
        findTroopButtonColors(x, startY, x + buttonWidth, startY + buttonHeight)    
    end
end

mSleep(3000)
initLog("color", 0)
saveColors()
closeLog("color")